<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>客户详情</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<style>
    /*.layui-input{height:30px;} !* layui-input 默认太高了，这里固定高度*!*/
    /*label.required:after {   !* 给红色的必填项打红色星号（文字后）如果打前面用before*!*/
    /*    content: ' *';*/
    /*    color: red;*/
    /*}*/
    .layui-form-label.required:after {   /* 这种写法也可以*/
        content: ' *';
        color: #ff0000;
    }
</style>
<body>
<div class="panel panel-default operation" >
    <div class="panel-heading title"></div>
    <div class="layui-card-body">
        <form class="layui-form " action="" lay-filter="info" style="width: 700px;margin-top: 10px">
            <input name="id" hidden/>
            <div class="layui-form-item">
                <label class="layui-form-label required">客户名称</label>
                <div class="layui-input-block">
                    <input type="khname" name="khname" placeholder="请输入客户名称" autocomplete="off"lay-verify="required"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">联系人</label>
                <div class="layui-input-block">
                    <input type="lxr" name="lxr" placeholder="请输入联系人" autocomplete="off" class="layui-input" lay-verify="required">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">联系电话</label>
                <div class="layui-input-block">
                    <input type="number" name="lxdh" placeholder="请输入联系电话" autocomplete="off" class="layui-input" lay-verify="required">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">其他电话</label>
                <div class="layui-input-block">
                    <input type="ssxs" name="qtdh" placeholder="多个电话时，用；分隔" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">客户来源</label>
                <div class="layui-input-block">
                    <select id="khlySCF" name="khly">
                        <option value="">请选择客户来源</option>
                    </select>
                </div>

            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">意向度</label>
                <div class="layui-input-block">
                    <select id="kujbSCF" name="khjb">
                        <option value="">请选择意向度</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <input type="bz" name="bz" placeholder="请输入备注" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item layui-hide">
                <div class="layui-input-block">
                    <span type="submit" class="layui-btn" lay-submit="" lay-filter="submit" id="submit">保存</span>
                    <span class="layui-btn layui-btn-primary" id="btn_cancel">返回</span>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="/layui/layui.js" charset="utf-8"></script>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script src="/js/jquery.js"></script>
<script src="/js/home.js?v=0.1"></script>
<script src="/js/common.js"></script>
</body>
<script>
//获取token
var token = CoreUtil.getData("access_token");
//地址栏转义token中的#号
var tokenQuery = token.replace("#", "%23");
var tableIns1;
var table = layui.table;
var form = layui.form;
var layer = layui.layer;
var $ = jQuery = layui.jquery;
var laydate = layui.laydate;
var upload = layui.upload;
info();
layui.use(['table', 'layer', 'laydate','form'], function () {
    //监听保存
    form.on('submit(submit)', function(data){
        CoreUtil.sendPost("/index/tWdkh/add",data.field,function (res) {
            if (res.code == 0){
                layer.msg("添加成功", {shade:0.4, icon:16, time:1000});
                parent.search();
            } else {
                layer.msg(res.msg, {shade:0.4, icon:16, time:1000});
            }
            parent.layer.close(1);
        });
    });
    //表单自定义验证
    form.verify({
        //验证下拉框是否为空
        DownFrame: function (value,item){
            if (value <= 0 || value == "" || value == null) {
                return '必填项不能为空';
            }
        },
        username: function(value, item){ //value：表单的值、item：表单的DOM对象
            if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                return '用户名不能有特殊字符';
            }
            if(/(^\_)|(\__)|(\_+$)/.test(value)){
                return '用户名首尾不能出现下划线\'_\'';
            }
            if(/^\d+\d+\d$/.test(value)){
                return '用户名不能全为数字';
            }
        }
    });

});

function info() {
    CoreUtil.sendGet("/tWdkh/infoData/", null, function (res) {

        var code = res.code;
        var data = res.data;
        //username、 khlySC 请选择客户来源、请选择意向度、请选择所属销售;
        if (code == 0) {
            //username
            var username = $("#username");
            $.each(data.username, function (index, item) {
                if (!!item) {
                    username.append("<option value=" + item + ">" + item + "</option>");
                }
            });
            //客户来源
            var khlySC = $("#khlySC");
            var khlySCF = $("#khlySCF");
            var khlySCFeidt = $("#khlySCFeidt");
            $.each(data.khly, function (index, item) {
                khlySC.append("<option value=" + item + ">" + item + "</option>");
                khlySCF.append("<option value=" + item + ">" + item + "</option>");
                khlySCFeidt.append("<option value=" + item + ">" + item + "</option>");
            });
            //意向度
            var kujbSC = $("#kujbSC");
            var kujbSCF = $("#kujbSCF");
            var kujbSCFeidt = $("#kujbSCFeidt");
            $.each(data.hkjb, function (index, item) {
                if (!!item) {
                    kujbSC.append("<option value=" + item.id + ">" + item.value + "</option>");
                    kujbSCF.append("<option value=" + item.id + ">" + item.value + "</option>");
                    kujbSCFeidt.append("<option value=" + item.id + ">" + item.value + "</option>");
                }
            });
            //所属销售
            var ssxsSC = $("#ssxsSC");
            $.each(data.ssxs, function (index, item) {
                if (!!item) {
                    ssxsSC.append("<option value=" + item + ">" + item + "</option>");
                }
            });
            form.render("select");
        }
    });
};
</script>
</html>